<template>
  <view class="container">
    <uni-section title="作业批改" type="line">
      <view class="example">

        <uni-forms ref="baseForm" :modelValue="baseFormData">
          <uni-forms-item label="作业
          标题" required>
            <uni-easyinput placeholder="请输入作业标题" v-model="homeworkDetail.homeWorkName"/>
          </uni-forms-item>
          <uni-forms-item label="作业
          内容" required>
            <uni-easyinput placeholder="请输入作业内容" v-model="homeworkDetail.homeWorkContent"/>
          </uni-forms-item>
		  <uni-forms-item label="参考答案">
            <uni-easyinput type="textarea" v-model="homeworkDetail.referenceAnswer" placeholder="请输入自我介绍"/>
          </uni-forms-item>
          <uni-forms-item label="学生作答">
            <uni-easyinput type="textarea" v-model="homeworkDetail.content" placeholder=""/>
          </uni-forms-item>
          <uni-forms-item label="作业评语">
            <uni-easyinput type="textarea" v-model="homeworkDetail.comment" @input="comment"/>
          </uni-forms-item>
        
        </uni-forms>
        <button type="primary" size="mini" @click="courect">AI批改</button>
        <button type="primary" size="mini" @click="submit">人工批改</button>
      </view>
    </uni-section>
  </view>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import {onLoad }from '@dcloudio/uni-app'
import apis from '../../api/apis'
// 基础表单数据
const baseFormData = reactive({
  name: '',
  age: '',
  introduction: '',
  sex: 2,
  hobby: [5]
});

// 表单引用
const baseFormRef = ref(null);
const homeworkDetail = ref({})
const homeworkJudge = async(id)=>{
	let res = await apis.getHomeworkData(id)
	console.log(res)
	homeworkDetail.value = res.data
}
const courseid = ref('')
onLoad((e)=>{
	courseid.value = e.id
	console.log(e.id)	
	homeworkJudge(e.id)
})
// console.log(courseid.value)
const comment = (e)=>{
	// console.log(e)
	homeworkDetail.value.comment = e
}

// 提交方法
const submit = async() => {
	let res = await apis.personalCorrect(homeworkDetail.value.homeWorkReplyId,homeworkDetail.value.comment,homeworkDetail.value.score)
	if(res.code === 200){
		uni.showToast({
			title:"批改成功"
		})
	}
};

const courect = async (id) =>{
	let res = await apis.aiCorrect(homeworkDetail.value.homeWorkReplyId)
	if(res.code === 200){
		
		homeworkDetail.comment = res.data.comment
		
		uni.showToast({
			title:"批改成功"
		})
		setTimeout(()=>{
			uni.redirectTo({
				url:'/pages/homeworkCorrect/homeworkCorrect?id='+courseid.value
			})
		},1500)
	}
}

</script>


<style lang="scss">
  .example {
    padding: 15px;
    background-color: #fff;
  }

  button {
    margin-left: 120rpx;
    margin-right: 50rpx;
  }
</style>